﻿using System.Collections.Generic;
using System.Text;
using msilgc.cbuilder;
using msilgc.cbuilder.CSyntaxTree;
using msilgc.cbuilder.MSILSyntaxTree;

namespace msilgc.CSyntaxTree {
    internal class CBasicBlock {
        public BasicBlock MsilBlock { get; set; }
        public string Label { get; set; }
        public List<ICStatement> Statements { get; set; }

        public CBasicBlock() {
            MsilBlock = null;
            Label = null;
            Statements = new List<ICStatement>();
        }

        public void Emit(StringBuilder builder, IMethodNameMapper methodNameMapper) {
            builder.AppendLine(string.Format("{0}:", Label));
            foreach (ICStatement statement in Statements) {
                if(statement is ICMethodCall) {
                    ICMethodCall methodCall = (ICMethodCall)statement;
                    methodCall.Emit(builder, methodNameMapper);
                } else {
                    statement.Emit(builder);
                }
            }
        }
    }
}
